/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.kpi.transport.servlet.actions.saving;

import ua.kpi.transport.servlet.actions.lists.TypesListAction;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ua.kpi.transport.db.dao.factory.DAOFactory;
import ua.kpi.transport.db.dao.factory.DBEnum;
import ua.kpi.transport.db.dao.interfaces.ITransportTypeDAO;
import ua.kpi.transport.db.entities.TransportTypeBean;
import ua.kpi.transport.servlet.actions.IAction;

/**
 *
 * @author harker777
 */
public class SaveTypeAction implements IAction{

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String name = request.getParameter("name");

        ITransportTypeDAO ttd = DAOFactory.getDAOFactory(DBEnum.MYSQL).getTransportTypeDAO();
        TransportTypeBean type = ttd.find(id);
        type.setName(name);
        ttd.update(type);
        
        return new TypesListAction().execute(request, response);
    }
    
}
